package com.sangeng.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.lang.reflect.Method;

@Repository
@Aspect
public class MyAspect {

    @Pointcut("execution(* com.sangeng.service..*.*(..))")
    public void pt() {
    }


//    @Before("pt()")
//    public void methodbefore() {
//        System.out.println("方法被调用了");
//    }

    @Before("pt()")
    public void before(JoinPoint joinPoint) {
        System.out.println("before");
    }

    @AfterReturning(value = "pt()", returning = "o")
    public void afterReturning(JoinPoint joinPoint, Object o) {
        System.out.println("afterReturning");

    }

    @After("pt()")
    public void after(JoinPoint joinPoint) {
        System.out.println("after");
    }

    @AfterThrowing(value = "pt()", throwing = "e")
    public void afterThrowing(JoinPoint joinPoint, Throwable e) {
        System.out.println("afterThrowing");
    }

    @Around("pt()")
    public void around(ProceedingJoinPoint point){
        //获取参数
        Object[] args = point.getArgs();
        try {
            Object proceed = point.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }


}
